package com.wanxi.servlet;

import com.wanxi.model.BrandModel;
import com.wanxi.model.UserModel;
import com.wanxi.service.BrandService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/go")
public class GoUpdatePageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        2.得到前端的值
        String id=req.getParameter("id");
//        3.封装到model
        BrandModel model=new BrandModel();
        model.setId(Tool.strToInt(id));
//        4.调用服务逻辑层
        BrandService brandService=new BrandService();
//        5.得到返回值结果
        BrandModel brandModel=brandService.findById(model);
//        6.返回结果到jsp页面
        req.setAttribute("brandModel",brandModel);
        req.getRequestDispatcher("/update.jsp").forward(req,resp);
    }
}
